package cn.biplam.back.services.log;

import cn.biplam.back.bean.sqlengine.function.FunctionFactory;
import cn.biplam.back.jda.Jda;
import cn.biplam.back.sql.dml.Insert;
import cn.biplam.common.bean.sqlengine.Sql;
import cn.biplam.common.client.DbResource;
import cn.biplam.common.paramters.SelectConstant.Function;
import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;

/**
 * 日志数据操作
 * @author 	WangSong 2009-3-12 上午10:43:13
 * @version 1.0
 */
public class LogData {

	@SuppressWarnings("unused")
	private int iId ;  
	private String sUserid  ;
	private String sPageid ;
	private String sPrompt ;
	private String sException ;
	@SuppressWarnings("unused")
	private int iSzfyId;


	/**
	 * 设置参数信息
	 * @param iId
	 * @param sUserid
	 * @param sPageid
	 * @param sPrompt
	 * @param sException
	 * @param iSzfyId
	 */
	public void set(int iId,String sUserid,String sPageid,
			String sPrompt,String sException,int iSzfyId){
		this.iId = iId;
		this.sUserid = sUserid;
		this.sPageid = sPageid;
		this.sPrompt = sPrompt;
		this.sException = sException;
		this.iSzfyId = iSzfyId;
	}

	/**
	 * 插入t_log表
	 * @return  boolean
	 * @throws ErrorMessage 
	 */
	public boolean insert() {
		boolean boo = false;
		try {
			DbResource mDbResource = new DbResource(DbResource.LOG);
			Jda mJda;

			mJda = new Jda(mDbResource);
			String date = new FunctionFactory().
			                 getFunction(mDbResource.getDbtype(),
					                     Function.SYSDATE);
			Insert insert = new Insert("SYS_LOG");
			insert.putStringFieldIgnoreNull("id", TOOLS.getId());
			insert.putStringFieldIgnoreNull("userid", sUserid);
			insert.putStringFieldIgnoreNull("pageid", sPageid);
			insert.putStringFieldIgnoreNull("prompt", sPrompt);
			insert.putFieldIgnoreNull("logtime", date);
			insert.putStringFieldIgnoreNull("exceptions", sException);
			
			Sql mSql = new Sql(insert.getSimpleSql());
			boo = mJda.executeDML(mSql);
		} catch (ErrorMessage e) {
			e.printStackTrace();
		}
		return boo;
	}
}
